﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using RBS.Common;
using RBS.Core.Model;
namespace RBS.Core.BLL {
	 	//广告券批次表
		public partial class P_Advertis_Batch
	{
   		     
		private readonly RBS.Core.DAL.P_Advertis_Batch dal=new RBS.Core.DAL.P_Advertis_Batch();
		public P_Advertis_Batch()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(RBS.Core.Model.P_Advertis_Batch model)
		{
						return dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(RBS.Core.Model.P_Advertis_Batch model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RBS.Core.Model.P_Advertis_Batch GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public RBS.Core.Model.P_Advertis_Batch GetModelByCache(int Id)
		{
			
			string CacheKey = "P_Advertis_BatchModel-" + Id;
			object objModel = RBS.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = RBS.Common.ConfigHelper.GetConfigInt("ModelCache");
						RBS.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (RBS.Core.Model.P_Advertis_Batch)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<RBS.Core.Model.P_Advertis_Batch> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<RBS.Core.Model.P_Advertis_Batch> DataTableToList(DataTable dt)
		{
			List<RBS.Core.Model.P_Advertis_Batch> modelList = new List<RBS.Core.Model.P_Advertis_Batch>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				RBS.Core.Model.P_Advertis_Batch model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new RBS.Core.Model.P_Advertis_Batch();					
													if(dt.Rows[n]["Id"].ToString()!="")
				{
					model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
				}
																																if(dt.Rows[n]["AP_Id"].ToString()!="")
				{
					model.AP_Id=int.Parse(dt.Rows[n]["AP_Id"].ToString());
				}
																																				model.BatchNo= dt.Rows[n]["BatchNo"].ToString();
																												if(dt.Rows[n]["BatchTime"].ToString()!="")
				{
					model.BatchTime=DateTime.Parse(dt.Rows[n]["BatchTime"].ToString());
				}
																																if(dt.Rows[n]["ABStatus"].ToString()!="")
				{
					model.ABStatus=int.Parse(dt.Rows[n]["ABStatus"].ToString());
				}
																										
				
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
#endregion


	    #region  ExtensionMethod
	    public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
	    {
            return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
	    }

	    #endregion  ExtensionMethod


        public int GetLave(int apid)
        {
            return dal.GetLave(apid);
        }
    }
}